home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / c_course.zip / COMPARES.C < prev    next >
Text File  |  1989-12-30  |  2KB  |  41 lines

  1. main()  /* This file will illustrate logical compares */
  2. {
  3. int x = 11,y = 11,z = 11;
  4. char a = 40,b = 40,c = 40;
  5. float r = 12.987,s = 12.987,t = 12.987;
  6.  
  7.                          /* First group of compare statements */
  8.  
  9.    if (x == y) z = -13;   /* This will set z = -13 */
  10.    if (x > z)  a = 'A';   /* This will set a = 65  */
  11.    if (!(x > z)) a = 'B'; /* This will change nothing */
  12.    if (b <= c) r = 0.0;   /* This will set r = 0.0 */
  13.    if (r != s) t = c/2;   /* This will set t = 20  */
  14.  
  15.                          /* Second group of compare statements */
  16.    
  17.    if (x = (r != s)) z = 1000; /* This will set x = some positive
  18.                                   number and z = 1000 */
  19.    if (x = y) z = 222;   /* This sets x = y, and z = 222 */
  20.    if (x != 0) z = 333;  /* This sets z = 333 */
  21.    if (x) z = 444;       /* This sets z = 444 */
  22.  
  23.                          /* Third group of compare statements */
  24.  
  25.    x = y = z = 77;
  26.    if ((x == y) && (x == 77)) z = 33; /* This sets z = 33 */
  27.    if ((x > y) || (z > 12))   z = 22; /* This sets z = 22 */
  28.    if (x && y && z) z = 11;           /* This sets z = 11 */
  29.    if ((x = 1) && (y = 2) && (z = 3)) r = 12.00; /* This sets
  30.                              x = 1, y = 2, z = 3, r = 12.00 */
  31.    if ((x == 2) && (y = 3) && (z = 4)) r = 14.56; /* This doesn't
  32.                              change anything */
  33.    
  34.                          /* Fourth group of compares */
  35.  
  36.    if (x == x); z = 27.345;  /* z always gets changed */
  37.    if (x != x)  z = 27.345;  /* Nothing gets changed */
  38.    if (x = 0)   z = 27.345;  /* This sets x = 0, z is unchanged */
  39.  
  40. }
  41.